package edu.dispatcher;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 重定向
 * sendRedirect()和setHeader()、setStatus()
 */
@WebServlet("/sendredirect01")
public class SendRedirect extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write("进入页面");

        /*response.setStatus(302);
        response.setHeader("location", "/targetweb");*/
        response.sendRedirect("/targetweb");

        writer.write("页面重定向完成");
    }
}
